package org.github.rayson517.easyplatform.common.web.base.entity;

import java.lang.reflect.Field;

import org.github.rayson517.easyplatform.common.web.annotation.Field2Column;
import org.github.rayson517.easyplatform.common.web.util.StrUtil;

import com.baomidou.mybatisplus.activerecord.Model;

public abstract class BaseModel<T extends Model> extends Model<T> {
	/**
	 * 
	 * @param sort 获取sort字段对应的数据库字段名
	 * @return 数据库字段名
	 */
	public String getColumn(String sort) {
		String column=null;
		try {
			Field field=this.getClass().getDeclaredField(sort);
			Field2Column fc=(Field2Column)field.getAnnotation(Field2Column.class);
			column=fc==null?StrUtil.HumpToUnderline(field.getName()):fc.value();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return column;
	}
}
